package spt.mc.demo;

import java.io.UnsupportedEncodingException;
import java.util.SortedMap;
import cn.hutool.http.HttpUtil;
import spt.mc.demo.constant.RunDataConstant;
import spt.mc.demo.entity.SendElevatorData;
import spt.mc.demo.util.MD5Util;

/**
 * 电梯数据采集对接demo
 * @author spt
 *
 */
public class ElevatorDataDemo {

	
	public static void main(String[] args) throws UnsupportedEncodingException {
		//发送电梯采集数据
		sendElevatorData();
	}

	
	//============发送电梯采集数据参照这个方法====================
  	public static void sendElevatorData() throws UnsupportedEncodingException {
  		SendElevatorData elevatorData=new SendElevatorData()
  				.setAppid(RunDataConstant.APPID)//*修改时必须要传AppId，不然鉴权通不过
  				//.setSn("31100000000000000002")
  				.setDeviceCode("311000867080X20130190")
  				//.setCode("170031")
  				.setIsIotOnline(1)
  				.setLiftRunningStatus(1)
  				.setRunningDirection(1)
  				.setAcceleration(0.6)
  				.setDeceleration(6D)
  				.setSpeed(1.76)
  				.setCurrentFloor(2)
  				.setDoorStatus(0)
  				.setIsOverload(1);
  		SortedMap<String, Object> map=elevatorData.converSortedMap(elevatorData);
  		long timestamp=System.currentTimeMillis();
  		String sign=MD5Util.createSign(map, RunDataConstant.SECRET,timestamp);
  		map.put("sign", sign);
  		map.put("timestamp", timestamp);
  		System.out.println(sign);
  		System.out.println(HttpUtil.post(RunDataConstant.SEND_API, map));
  	}
}
